//
//  HLSettingLogoutViewController.m
//  YueYue
//
//  Created by hulu001 on 2023/5/19.
//

#import "HLSettingLogoutViewController.h"
#import "HLUserOptionRequest.h"

@interface HLSettingLogoutViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) QMUIButton *startButton;

@end

@implementation HLSettingLogoutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = HLBackgroundColor;
}

- (void)setupNavigationItems
{
    [super setupNavigationItems];
    self.title = @"注销账号";
}

- (void)initSubviews
{
    [super initSubviews];
    self.scrollView = [[UIScrollView alloc] init];
    [self.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    self.scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    self.contentView = [[UIView alloc] init];
    [self.scrollView addSubview:_contentView];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = UIColorBlack;
    _titleLabel.font = UIFontMake(20);
    _titleLabel.text = @"注销须知";
    [_contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(NavigationContentTopConstant + 24);
    }];
    
    self.contentLabel = [[UILabel alloc] init];
    _contentLabel.textColor = HLTextColor2;
    _contentLabel.font = UIFontMake(15);
    _contentLabel.numberOfLines = 0;
    _contentLabel.qmui_lineHeight = 26.0;
    _contentLabel.text = @"您的账号存在末处理事项，如您选择继续注销，请认真阅读以下重要提醒。账号注销后，您将无法再使用该账号，包括但不限于：\n1.无法登录、使用当前账号，并移除该账号下所有登录方式；\n2.账号头像重置为默认头像、昵称重置为“用户已注销”；\n3.移除该账号下的实名认证信息；\n4.该账号下的个人资料和历史信息都将无法找回；\n5.取消所有认证身份且无法恢复；\n6.取消会员身份且无法恢复；\n7.账号中所有的资产及权益被清除；";
    [_contentView addSubview:_contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.equalTo(_titleLabel.mas_bottom).offset(24);
    }];

    
    self.startButton = [[QMUIButton alloc] init];
    [_startButton setTitle:@"确认" forState:UIControlStateNormal];
    [_startButton setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [_startButton.titleLabel setFont:UIFontMake(15)];
    [_startButton addTarget:self action:@selector(logoutAccount) forControlEvents:UIControlEventTouchUpInside];
    _startButton.cornerRadius = 4;
    [_startButton setBackgroundColor:HLMainColor];
    [self.view addSubview:_startButton];
    [_startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_contentLabel);
        make.height.mas_equalTo(52);
        make.bottom.mas_equalTo(-(SafeAreaInsetsConstantForDeviceWithNotch.bottom + 40));
    }];
    
    self.tipLabel = [[UILabel alloc] init];
    _tipLabel.textColor = HLTextColor2;
    _tipLabel.font = UIFontMake(15);
    _tipLabel.numberOfLines = 0;
    _tipLabel.text = @"若您已确认并满足以上条件，请点击确认操作";
    [self.view addSubview:_tipLabel];
    [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_startButton);
        make.bottom.equalTo(_startButton.mas_top).offset(-18);
    }];

    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_contentLabel.mas_bottom).offset(44);
    }];

    
}

- (void)saveAction
{
    [HLUIHelper showAlertWithContent:@"确认注销此账号!" callBack:^(BOOL isConfirm) {
        if (isConfirm){
            [self logoutAccount];
        }
    }];
}

- (void)logoutAccount
{
    HLUserOptionRequest *userOPRequest = [[HLUserOptionRequest alloc] initWithType:HLUserOptionTypeLogout params:@{}];
    [userOPRequest startWithCompletionBlockWithSuccess:^(__kindof HLUserOptionRequest * _Nonnull request) {
        if (request.isSuccess){
            [HLHelper logout];
            [HLUIHelper setRootLogin];
        }
    } failure:nil];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDarkContent;
}

- (UIImage *)qmui_navigationBarBackgroundImage
{
    return [UIImage qmui_imageWithColor:HLBackgroundColor];
}

- (nullable UIColor *)qmui_navigationBarTintColor
{
    return UIColorBlack;
}

@end
